<div id="panel-button" class="row">
	<div class="col-md-12">
		<div class="panel panel-default">
			<div class="panel-body text-right">
				{{Form::button(trans('form.save'), array('class' => 'btn btn-primary', 'id' => 'submit'))}}
				@if(isset($refund->id))
				{{Form::button(trans('form.delete'), array('class' => 'btn btn-danger', 'id' => 'delete', 'data-id' => $refund->id))}}
				@endif
				{{Form::button(trans('form.back'), array('class' => 'btn btn-default', 'id' => 'cancel'))}}
			</div>
		</div>
	</div>
</div>

<div id="panel-button-fixed" class="row hidden">
	<div class="col-md-12">
		<div class="panel panel-default">
			<div class="panel-body text-right">
				{{Form::button(trans('form.save'), array('class' => 'btn btn-primary', 'id' => 'submit'))}}
				@if(isset($refund->id))
				{{Form::button(trans('form.delete'), array('class' => 'btn btn-danger', 'id' => 'delete', 'data-id' => $refund->id))}}
				@endif
				{{Form::button(trans('form.back'), array('class' => 'btn btn-default', 'id' => 'cancel'))}}
			</div>
		</div>
	</div>
</div>

<div id="panel-error" class="row hidden">
	<div class="col-md-12">
		<div class="panel panel-default">
			<div id="error-content" class="panel-body"></div>
		</div>
	</div>
</div>

<div class='row'>
	<div class='col-md-12'>
		<div class="panel panel-default">
			<div class="panel-body">
				{{Form::open(array('method' => 'post', 'class' => 'form-horizontal'))}}
					<div class="form-group">
						{{Form::label('total', trans('refund.total'), array('class' => 'col-sm-2 control-label'))}}
						<div class="col-sm-5">
							{{Form::text('total', (isset($refund->total))? $refund->total : 0, array('class' => 'form-control', 'id' => 'total', 'placeholder' => trans('refund.total')))}}
						</div>
					</div>

					<div class="form-group">
						{{Form::label('date', trans('order.date'), array('class' => 'col-sm-2 control-label'))}}
						<div class="col-sm-5">
							{{Form::text('date', date("d-m-Y"), array('class' => 'form-control', 'id' => 'date'))}}
						</div>
					</div>

					{{Form::hidden('id', (isset($customer->id))? $customer->id : 0, array('id' => 'id'))}}
					{{Form::hidden('type', 'refund', array('id' => 'type'))}}
				{{Form::close()}}
			</div>
		</div>
	</div>
</div>

<script>
$(document).ready(function(){
	$("input#date").change(function(event) {
		$("#submit").focus();
	});

	$("#submit").click(function(){
		var total = $("#total").val();
		var date  = $("#date").val();

		deleteErrorMessages();

		$.ajax({
			url: "{{URL::to('/admin/refund/create')}}",
			type: "POST",
			beforeSend: ajaxLoading(),
			data: {'total': total, 'date': date, 'customer': {{$customer->id}}},
			success: function(result){
				var rs = $.parseJSON(result);
				
				if(rs.error == true){
					appendErrorMessages(rs.message);
				}else{
					window.location = "{{URL::to('/admin/customer')}}";
				}

				ajaxLoadSuccess();
			}
		});
	});

	$("button#delete").click(function(){
		var ok = confirm("{{trans('customer.confirm_delete_this')}}");

		if(ok){
			var id = $(this).attr('data-id');

			$.ajax({
				url: '{{URL::to("admin/customer/delete")}}',
				type: 'POST',
				data: {'id': id},
				success: function(result){
					var url = "{{URL::to('/admin/customer/')}}";

					window.location = url;
				}
			});
		}
	});

	$("button#cancel").click(function(){
		var url = "{{URL::to('/admin/refund/')}}";

		window.location = url;
	});
});
</script>